package com.flower.controller;

import com.flower.entity.Order;
import com.flower.mapper.OrderMapper;
import com.flower.service.OrderService;
import com.common.baseModel.JsonResult;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName OrderController
 * @Description TODO
 * @Author 张晓焕
 * @Date 2022/6/10 11:16
 * @Version 1.0
 */
@Api("订单测试")
@RestController
public class OrderController {
    @Autowired
    OrderService orderService;

    @Autowired
    OrderMapper orderMapper ;

    @GlobalTransactional
    @ShardingTransactionType(TransactionType.BASE)
    @ApiOperation("订单插入测试")
    @PostMapping("/insert")
    public JsonResult<Object> insertOrder(){
        for(int i = 0 ; i < 10 ; i ++){
            Order order = new Order();
           // order.setTid(Long.valueOf(i));
            order.setTname("订单2"+i);
            order.setGoodsId(Long.valueOf(""+(new Random(100).nextInt())));
            order.setTstatus("1");
            orderMapper.insert(order);
        }
        return  JsonResult.isOk();
    }

    @ApiOperation("/并发测试")
    @PostMapping("/testSync")
    public JsonResult<Object> testAsyc() throws ExecutionException, InterruptedException {
        int a=1/0;
        return JsonResult.isOk();
    }
}
